{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0.0\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "print(tf.__version__)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 批量归一化\n",
    "\n",
    "本节我们介绍批量归一化（batch normalization）层，它能让较深的神经网络的训练变得更加容易 [1]。在 “[实战Kaggle比赛：预测房价](http://zh.d2l.ai/chapter_deep-learning-basics/kaggle-house-price.html)” 一节里，我们对输入数据做了标准化处理：处理后的任意一个特征在数据集中所有样本上的均值为0、标准差为1。标准化处理输入数据使各个特征的分布相近：这往往更容易训练出有效的模型。\n",
    "\n",
    "通常来说，数据标准化预处理对于浅层模型就足够有效了。随着模型训练的进行，当每层中参数更新时，靠近输出层的输出较难出现剧烈变化。但对深层神经网络来说，即使输入数据已做标准化，训练中模型参数的更新依然很容易造成靠近输出层输出的剧烈变化。这种计算数值的不稳定性通常令我们难以训练出有效的深度模型。\n",
    "\n",
    "批量归一化的提出正是为了应对深度模型训练的挑战。在模型训练时，批量归一化利用小批量上的均值和标准差，不断调整神经网络中间输出，从而使整个神经网络在各层的中间输出的数值更稳定。批量归一化和下一节将要介绍的残差网络为训练和设计深度模型提供了两类重要思路。\n",
    "\n",
    "## 5.10.1 批量归一化层\n",
    "\n",
    "对全连接层和卷积层做批量归一化的方法稍有不同。下面我们将分别介绍这两种情况下的批量归一化。\n",
    "\n",
    "### 5.10.1.1. 对全连接层做批量归一化\n",
    "我们先考虑如何对全连接层做批量归一化。通常，我们将批量归一化层置于全连接层中的仿射变换和激活函数之间。设全连接层的输入为$\\boldsymbol{u}$，权重参数和偏差参数分别为$\\boldsymbol{W}$和$\\boldsymbol{b}$，，激活函数为ϕ。设批量归一化的运算符为$\\boldsymbol{BN}$。那么，使用批量归一化的全连接层的输出为：\n",
    "$$\\phi(\\text{BN}(\\boldsymbol{x})),$$\n",
    "其中批量归一化输入由$\\boldsymbol{x}$仿射变换\n",
    "$$\\boldsymbol{x} = \\boldsymbol{W\\boldsymbol{u} + \\boldsymbol{b}}$$\n",
    "得到。考虑一个由m个样本组成的小批量，仿射变换的输出为一个新的小批量$\\mathcal{B} = \\{\\boldsymbol{x}^{(1)}, \\ldots, \\boldsymbol{x}^{(m)} \\}$。它们正是批量归一化层的输入。对于小批量$\\mathcal{B}$中任意样本$\\boldsymbol{x}^{(i)} \\in \\mathbb{R}^d, 1 \\leq i \\leq m$，批量归一化层的输出同样是$\\boldsymbol{d}$维向量\n",
    "$$\\boldsymbol{y}^{(i)} = \\text{BN}(\\boldsymbol{x}^{(i)}),$$\n",
    "并由以下几步求得。首先，对小批量$\\mathcal{B}$求均值和方差：\n",
    "$$\\boldsymbol{\\mu}_\\mathcal{B} \\leftarrow \\frac{1}{m}\\sum_{i = 1}^{m} \\boldsymbol{x}^{(i)},$$\n",
    "$$\\boldsymbol{\\sigma}_\\mathcal{B}^2 \\leftarrow \\frac{1}{m} \\sum_{i=1}^{m}(\\boldsymbol{x}^{(i)} - \\boldsymbol{\\mu}_\\mathcal{B})^2,$$\n",
    "其中的平方计算是按元素求平方。接下来，使用按元素开方和按元素除法对$\\boldsymbol{x}^{(i)}$标准化：\n",
    "$$\\hat{\\boldsymbol{x}}^{(i)} \\leftarrow \\frac{\\boldsymbol{x}^{(i)} - \\boldsymbol{\\mu}_\\mathcal{B}}{\\sqrt{\\boldsymbol{\\sigma}_\\mathcal{B}^2 + \\epsilon}},$$\n",
    "这里$\\epsilon > 0$是一个很小的常数，保证分母大于0。在上面标准化的基础上，批量归一化层引入了两个可以学习的模型参数，拉伸（scale）参数$\\boldsymbol{\\gamma}$和偏移（shift）参数$\\boldsymbol{\\beta}$。这两个参数和$\\boldsymbol{x}^{(i)}$形状相同，皆为d维向量。它们与$\\hat{\\boldsymbol{x}}^{(i)}$分别做按元素乘法（符号$\\odot$）和加法计算：\n",
    "$${\\boldsymbol{y}}^{(i)} \\leftarrow \\boldsymbol{\\gamma} \\odot \\hat{\\boldsymbol{x}}^{(i)} + \\boldsymbol{\\beta}.$$\n",
    "至此，我们得到了$\\boldsymbol{x}^{(i)}$的批量归一化的输出$\\boldsymbol{y}^{(i)}$。 值得注意的是，可学习的拉伸和偏移参数保留了不对$\\boldsymbol{x}^{(i)}$做批量归一化的可能：此时只需学出$\\boldsymbol{\\gamma} = \\sqrt{\\boldsymbol{\\sigma}_\\mathcal{B}^2 + \\epsilon}$和$\\boldsymbol{\\beta} = \\boldsymbol{\\mu}_\\mathcal{B}$。我们可以对此这样理解：如果批量归一化无益，理论上，学出的模型可以不使用批量归一化。\n",
    "\n",
    "### 5.10.1.2. 对卷积层做批量归一化\n",
    "对卷积层来说，批量归一化发生在卷积计算之后、应用激活函数之前。如果卷积计算输出多个通道，我们需要对这些通道的输出分别做批量归一化，且每个通道都拥有独立的拉伸和偏移参数，并均为标量。设小批量中有 m个样本。在单个通道上，假设卷积计算输出的高和宽分别为 p和 q 。我们需要对该通道中 m×p×q个元素同时做批量归一化。对这些元素做标准化计算时，我们使用相同的均值和方差，即该通道中 m×p×q个元素的均值和方差。\n",
    "\n",
    "### 5.10.1.3. 预测时的批量归一化\n",
    "使用批量归一化训练时，我们可以将批量大小设得大一点，从而使批量内样本的均值和方差的计算都较为准确。将训练好的模型用于预测时，我们希望模型对于任意输入都有确定的输出。因此，单个样本的输出不应取决于批量归一化所需要的随机小批量中的均值和方差。一种常用的方法是通过移动平均估算整个训练数据集的样本均值和方差，并在预测时使用它们得到确定的输出。可见，和丢弃层一样，批量归一化层在训练模式和预测模式下的计算结果也是不一样的。\n",
    "\n",
    "## 5.10.2. 从零开始实现\n",
    "下面我们通过numpy中的ndarray来实现批量归一化层。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def batch_norm(is_training,X, gamma, beta, moving_mean, moving_var, eps, momentum):\n",
    "    # 判断是当前模式是训练模式还是预测模式\n",
    "    if not is_training:\n",
    "        # 如果是在预测模式下，直接使用传入的移动平均所得的均值和方差\n",
    "        X_hat = (X - moving_mean) / np.sqrt(moving_var + eps)\n",
    "    else:\n",
    "        assert len(X.shape) in (2, 4)\n",
    "        if len(X.shape) == 2:\n",
    "            # 使用全连接层的情况，计算特征维上的均值和方差\n",
    "            mean = X.mean(axis=0)\n",
    "            var = ((X - mean) ** 2).mean(axis=0)\n",
    "        else:\n",
    "            # 使用二维卷积层的情况，计算通道维上（axis=1）的均值和方差。这里我们需要保持\n",
    "            # X的形状以便后面可以做广播运算\n",
    "            mean = X.mean(axis=(0, 2, 3), keepdims=True)\n",
    "            var = ((X - mean) ** 2).mean(axis=(0, 2, 3), keepdims=True)\n",
    "        # 训练模式下用当前的均值和方差做标准化\n",
    "        X_hat = (X - mean) / np.sqrt(var + eps)\n",
    "        # 更新移动平均的均值和方差\n",
    "        moving_mean = momentum * moving_mean + (1.0 - momentum) * mean\n",
    "        moving_var = momentum * moving_var + (1.0 - momentum) * var\n",
    "    Y = gamma * X_hat + beta  # 拉伸和偏移\n",
    "    return Y, moving_mean, moving_var"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "接下来，我们自定义一个BatchNorm层。它保存参与求梯度和迭代的拉伸参数gamma和偏移参数beta，同时也维护移动平均得到的均值和方差，以便能够在模型预测时被使用。BatchNorm实例所需指定的num_features参数对于全连接层来说应为输出个数，对于卷积层来说则为输出通道数。该实例所需指定的num_dims参数对于全连接层和卷积层来说分别为2和4。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "class BatchNormalization(tf.keras.layers.Layer):\n",
    "    def __init__(self, decay=0.9, epsilon=1e-5, **kwargs):\n",
    "        self.decay = decay\n",
    "        self.epsilon = epsilon\n",
    "        super(BatchNormalization, self).__init__(**kwargs)\n",
    "\n",
    "    def build(self, input_shape):\n",
    "        self.gamma = self.add_weight(name='gamma',\n",
    "                                     shape=[input_shape[-1], ],\n",
    "                                     initializer=tf.initializers.ones,\n",
    "                                     trainable=True)\n",
    "        self.beta = self.add_weight(name='beta',\n",
    "                                    shape=[input_shape[-1], ],\n",
    "                                    initializer=tf.initializers.zeros,\n",
    "                                    trainable=True)\n",
    "        self.moving_mean = self.add_weight(name='moving_mean',\n",
    "                                           shape=[input_shape[-1], ],\n",
    "                                           initializer=tf.initializers.zeros,\n",
    "                                           trainable=False)\n",
    "        self.moving_variance = self.add_weight(name='moving_variance',\n",
    "                                               shape=[input_shape[-1], ],\n",
    "                                               initializer=tf.initializers.ones,\n",
    "                                               trainable=False)\n",
    "        super(BatchNormalization, self).build(input_shape)\n",
    "\n",
    "    def assign_moving_average(self, variable, value):\n",
    "        \"\"\"\n",
    "        variable = variable * decay + value * (1 - decay)\n",
    "        \"\"\"\n",
    "        delta = variable * self.decay + value * (1 - self.decay)\n",
    "        return variable.assign(delta)\n",
    "\n",
    "    @tf.function\n",
    "    def call(self, inputs, training):\n",
    "        if training:\n",
    "            batch_mean, batch_variance = tf.nn.moments(inputs, list(range(len(inputs.shape) - 1)))\n",
    "            mean_update = self.assign_moving_average(self.moving_mean, batch_mean)\n",
    "            variance_update = self.assign_moving_average(self.moving_variance, batch_variance)\n",
    "            self.add_update(mean_update)\n",
    "            self.add_update(variance_update)\n",
    "            mean, variance = batch_mean, batch_variance\n",
    "        else:\n",
    "            mean, variance = self.moving_mean, self.moving_variance\n",
    "        output = tf.nn.batch_normalization(inputs,\n",
    "                                           mean=mean,\n",
    "                                           variance=variance,\n",
    "                                           offset=self.beta,\n",
    "                                           scale=self.gamma,\n",
    "                                           variance_epsilon=self.epsilon)\n",
    "        return output\n",
    "\n",
    "    def compute_output_shape(self, input_shape):\n",
    "        return input_shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.10.2.1. 使用批量归一化层的LeNet\n",
    "\n",
    "下面我们修改“[卷积神经网络（LeNet）](http://zh.d2l.ai/chapter_convolutional-neural-networks/lenet.html)”这一节介绍的LeNet模型，从而应用批量归一化层。我们在所有的卷积层或全连接层之后、激活层之前加入批量归一化层。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "net = tf.keras.models.Sequential(\n",
    "    [tf.keras.layers.Conv2D(filters=6,kernel_size=5),\n",
    "    BatchNormalization(),\n",
    "    tf.keras.layers.Activation('sigmoid'),\n",
    "    tf.keras.layers.MaxPool2D(pool_size=2, strides=2),\n",
    "    tf.keras.layers.Conv2D(filters=16,kernel_size=5),\n",
    "    BatchNormalization(),\n",
    "    tf.keras.layers.Activation('sigmoid'),\n",
    "    tf.keras.layers.MaxPool2D(pool_size=2, strides=2),\n",
    "    tf.keras.layers.Flatten(),\n",
    "    tf.keras.layers.Dense(120),\n",
    "    BatchNormalization(),\n",
    "    tf.keras.layers.Activation('sigmoid'),\n",
    "    tf.keras.layers.Dense(84),\n",
    "    BatchNormalization(),\n",
    "    tf.keras.layers.Activation('sigmoid'),\n",
    "    tf.keras.layers.Dense(10,activation='sigmoid')]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下面我们训练修改后的模型。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 48000 samples, validate on 12000 samples\n",
      "Epoch 1/5\n",
      "48000/48000 [==============================] - 25s 526us/sample - loss: 0.4030 - accuracy: 0.9416 - val_loss: 0.2181 - val_accuracy: 0.9346\n",
      "Epoch 2/5\n",
      "48000/48000 [==============================] - 23s 470us/sample - loss: 0.0823 - accuracy: 0.9773 - val_loss: 0.0782 - val_accuracy: 0.9774\n",
      "Epoch 3/5\n",
      "48000/48000 [==============================] - 22s 457us/sample - loss: 0.0616 - accuracy: 0.9816 - val_loss: 0.0935 - val_accuracy: 0.9721\n",
      "Epoch 4/5\n",
      "48000/48000 [==============================] - 24s 498us/sample - loss: 0.0508 - accuracy: 0.9847 - val_loss: 0.0947 - val_accuracy: 0.9720\n",
      "Epoch 5/5\n",
      "48000/48000 [==============================] - 28s 574us/sample - loss: 0.0447 - accuracy: 0.9861 - val_loss: 0.2494 - val_accuracy: 0.9176\n",
      "10000/1 - 1s - loss: 0.2494 - accuracy: 0.9216\n",
      "Test loss: 0.24052143813222646\n",
      "Test accuracy: 0.9216\n"
     ]
    }
   ],
   "source": [
    "(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\n",
    "x_train = x_train.reshape((60000, 28, 28, 1)).astype('float32') / 255\n",
    "x_test = x_test.reshape((10000, 28, 28, 1)).astype('float32') / 255\n",
    "\n",
    "net.compile(loss='sparse_categorical_crossentropy',\n",
    "              optimizer=tf.keras.optimizers.RMSprop(),\n",
    "              metrics=['accuracy'])\n",
    "history = net.fit(x_train, y_train,\n",
    "                    batch_size=64,\n",
    "                    epochs=5,\n",
    "                    validation_split=0.2)\n",
    "test_scores = net.evaluate(x_test, y_test, verbose=2)\n",
    "print('Test loss:', test_scores[0])\n",
    "print('Test accuracy:', test_scores[1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最后我们查看第一个批量归一化层学习到的拉伸参数gamma和偏移参数beta。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<tf.Variable 'sequential/batch_normalization/gamma:0' shape=(6,) dtype=float32, numpy=\n",
       " array([0.93455726, 1.0476167 , 1.0069158 , 0.9169525 , 1.4070569 ,\n",
       "        0.9973122 ], dtype=float32)>,\n",
       " <tf.Variable 'sequential/batch_normalization/beta:0' shape=(6,) dtype=float32, numpy=\n",
       " array([-0.64863527, -0.26409525, -0.60552806,  0.00235984,  0.25987023,\n",
       "        -0.38496298], dtype=float32)>)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "net.get_layer(index=1).gamma,net.get_layer(index=1).beta"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.10.3 简洁实现\n",
    "\n",
    "与我们刚刚自己定义的`BatchNorm`类相比，keras中`layers`模块定义的`BatchNorm`类使用起来更加简单。它不需要指定自己定义的`BatchNorm`类中所需的`num_features`和`num_dims`参数值。在keras中，这些参数值都将通过延后初始化而自动获取。下面我们用keras实现使用批量归一化的LeNet。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "net = tf.keras.models.Sequential()\n",
    "net.add(tf.keras.layers.Conv2D(filters=6,kernel_size=5))\n",
    "net.add(tf.keras.layers.BatchNormalization())\n",
    "net.add(tf.keras.layers.Activation('sigmoid'))\n",
    "net.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))\n",
    "net.add(tf.keras.layers.Conv2D(filters=16,kernel_size=5))\n",
    "net.add(tf.keras.layers.BatchNormalization())\n",
    "net.add(tf.keras.layers.Activation('sigmoid'))\n",
    "net.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))\n",
    "net.add(tf.keras.layers.Flatten())\n",
    "net.add(tf.keras.layers.Dense(120))\n",
    "net.add(tf.keras.layers.BatchNormalization())\n",
    "net.add(tf.keras.layers.Activation('sigmoid'))\n",
    "net.add(tf.keras.layers.Dense(84))\n",
    "net.add(tf.keras.layers.BatchNormalization())\n",
    "net.add(tf.keras.layers.Activation('sigmoid'))\n",
    "net.add(tf.keras.layers.Dense(10,activation='sigmoid'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用同样的超参数进行训练。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 48000 samples, validate on 12000 samples\n",
      "Epoch 1/5\n",
      "48000/48000 [==============================] - 27s 553us/sample - loss: 0.0383 - accuracy: 0.9877 - val_loss: 0.1457 - val_accuracy: 0.9581\n",
      "Epoch 2/5\n",
      "48000/48000 [==============================] - 25s 511us/sample - loss: 0.0342 - accuracy: 0.9890 - val_loss: 0.1359 - val_accuracy: 0.9613\n",
      "Epoch 3/5\n",
      "48000/48000 [==============================] - 22s 467us/sample - loss: 0.0296 - accuracy: 0.9907 - val_loss: 0.1943 - val_accuracy: 0.9402\n",
      "Epoch 4/5\n",
      "48000/48000 [==============================] - 23s 476us/sample - loss: 0.0285 - accuracy: 0.9910 - val_loss: 0.7860 - val_accuracy: 0.8291\n",
      "Epoch 5/5\n",
      "48000/48000 [==============================] - 23s 478us/sample - loss: 0.0234 - accuracy: 0.9927 - val_loss: 0.0897 - val_accuracy: 0.9732\n",
      "10000/1 - 1s - loss: 0.0416 - accuracy: 0.9726\n",
      "Test loss: 0.08218458472136408\n",
      "Test accuracy: 0.9726\n"
     ]
    }
   ],
   "source": [
    "(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()\n",
    "x_train = x_train.reshape((60000, 28, 28, 1)).astype('float32') / 255\n",
    "x_test = x_test.reshape((10000, 28, 28, 1)).astype('float32') / 255\n",
    "\n",
    "net.compile(loss='sparse_categorical_crossentropy',\n",
    "              optimizer=tf.keras.optimizers.RMSprop(),\n",
    "              metrics=['accuracy'])\n",
    "history = net.fit(x_train, y_train,\n",
    "                    batch_size=64,\n",
    "                    epochs=5,\n",
    "                    validation_split=0.2)\n",
    "test_scores = net.evaluate(x_test, y_test, verbose=2)\n",
    "print('Test loss:', test_scores[0])\n",
    "print('Test accuracy:', test_scores[1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.10.4 小结\n",
    "\n",
    "* 在模型训练时，批量归一化利用小批量上的均值和标准差，不断调整神经网络的中间输出，从而使整个神经网络在各层的中间输出的数值更稳定。\n",
    "* 对全连接层和卷积层做批量归一化的方法稍有不同。\n",
    "* 批量归一化层和丢弃层一样，在训练模式和预测模式的计算结果是不一样的。\n",
    "* keras提供的BatchNorm类使用起来简单、方便。\n",
    "\n",
    "\n",
    "## 5.10.4 练习\n",
    "\n",
    "* 能否将批量归一化前的全连接层或卷积层中的偏差参数去掉？为什么？（提示：回忆批量归一化中标准化的定义。）\n",
    "* 尝试调大学习率。同[“卷积神经网络（LeNet）”](lenet.ipynb)一节中未使用批量归一化的LeNet相比，现在是不是可以使用更大的学习率？\n",
    "* 尝试将批量归一化层插入LeNet的其他地方，观察并分析结果的变化。\n",
    "* 尝试一下不学习拉伸参数`gamma`和偏移参数`beta`（构造的时候加入参数`grad_req='null'`来避免计算梯度），观察并分析结果。\n",
    "* 查看`BatchNorm`类的文档来了解更多使用方法，例如，如何在训练时使用基于全局平均的均值和方差。\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 5.10.4 参考文献\n",
    "\n",
    "[1] Ioffe, S., & Szegedy, C. (2015). Batch normalization: Accelerating deep network training by reducing internal covariate shift. arXiv preprint arXiv:1502.03167."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": false,
   "autoclose": true,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": false,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
